using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace DTO
{
	/// <summary> 
	///Author: nnamthach@gmail.com 
	/// <summary>
	
    public class RateInfo
    {
		#region Local Variable
		public enum Field
		{
			ID,
			UserID,
			ProductID,
			DateTime,
			Rate,
			Comment,
			Rank
		}
		private Int32 _ID;
		private Int32 _UserID;
		private Int32 _ProductID;
		private DateTime _DateTime;
		private Double _Rate;
		private String _Comment;
		private String _Rank;
		
		public Int32 ID{	get{ return _ID;} set{_ID = value;} }
		public Int32 UserID{	get{ return _UserID;} set{_UserID = value;} }
		public Int32 ProductID{	get{ return _ProductID;} set{_ProductID = value;} }
		public DateTime DateTime{	get{ return _DateTime;} set{_DateTime = value;} }
		public Double Rate{	get{ return _Rate;} set{_Rate = value;} }
		public String Comment{	get{ return _Comment;} set{_Comment = value;} }
		public String Rank{	get{ return _Rank;} set{_Rank = value;} }
		
        #endregion LocalVariable
        
        #region Constructor
		public RateInfo()
		{
			_ID = 0;
			_UserID = 0;
			_ProductID = 0;
			_DateTime = DateTime.Now;
			_Rate = 0;
			_Comment = "";
			_Rank = "";
		}
		public RateInfo(
		Int32 ID,
		Int32 UserID,
		Int32 ProductID,
		DateTime DateTime,
		Double Rate,
		String Comment,
		String Rank
		)
		{
			_ID = ID;
			_UserID = UserID;
			_ProductID = ProductID;
			_DateTime = DateTime;
			_Rate = Rate;
			_Comment = Comment;
			_Rank = Rank;
		}
		public RateInfo(DataRow dr)
		{
			if (dr != null)
			{
				_ID = dr[Field.ID.ToString()] == DBNull.Value?0:Convert.ToInt32(dr[Field.ID.ToString()]);
				_UserID = dr[Field.UserID.ToString()] == DBNull.Value?0:Convert.ToInt32(dr[Field.UserID.ToString()]);
				_ProductID = dr[Field.ProductID.ToString()] == DBNull.Value?0:Convert.ToInt32(dr[Field.ProductID.ToString()]);
				_DateTime = dr[Field.DateTime.ToString()] == DBNull.Value?DateTime.Now:Convert.ToDateTime(dr[Field.DateTime.ToString()]);
				_Rate = dr[Field.Rate.ToString()] == DBNull.Value?0:Convert.ToDouble(dr[Field.Rate.ToString()]);
				_Comment = dr[Field.Comment.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Comment.ToString()]);
				_Rank = dr[Field.Rank.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Rank.ToString()]);
			}
		}
		public RateInfo(RateInfo objEntr)
		{			
			_ID = objEntr.ID;			
			_UserID = objEntr.UserID;			
			_ProductID = objEntr.ProductID;			
			_DateTime = objEntr.DateTime;			
			_Rate = objEntr.Rate;			
			_Comment = objEntr.Comment;			
			_Rank = objEntr.Rank;			
		}
        #endregion Constructor
        
        #region InitTable
		public static DataTable ToDataTable()
		{
			DataTable dt = new DataTable("Rate");
			dt.Columns.AddRange(new DataColumn[] { 
				new DataColumn(Field.ID.ToString(), typeof(Int32)),
				new DataColumn(Field.UserID.ToString(), typeof(Int32)),
				new DataColumn(Field.ProductID.ToString(), typeof(Int32)),
				new DataColumn(Field.DateTime.ToString(), typeof(DateTime)),
				new DataColumn(Field.Rate.ToString(), typeof(Double)),
				new DataColumn(Field.Comment.ToString(), typeof(String)),
				new DataColumn(Field.Rank.ToString(), typeof(String))
			});
			return dt;
		}
		public DataRow ToDataRow(DataTable dt)
		{
			DataRow row = dt.NewRow();
			row[Field.ID.ToString()] = _ID;
			row[Field.UserID.ToString()] = _UserID;
			row[Field.ProductID.ToString()] = _ProductID;
			row[Field.DateTime.ToString()] = _DateTime;
			row[Field.Rate.ToString()] = _Rate;
			row[Field.Comment.ToString()] = _Comment;
			row[Field.Rank.ToString()] = _Rank;
			return row;
		}
        #endregion InitTable
    }
}
